﻿<html>
	<head>
		<title>Felhasználók listája</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<link rel="stylesheet" href="v-a.css" type="text/css">
	</head>
	<?php	
		session_start();
		require_once ('dbConnect.php');
		include ('functions.php');

		if(isset($_POST['Vissza'])) {
			$_SESSION['uzenet']="";
			header('Location: index.php');
			exit;
		}
		if(isset($_POST['Newuser'])) {
			$_SESSION['uzenet']="";
			$_SESSION['vissza']="userlist.php";
			header('Location: newuser.php');
			exit;
		}
		if(isset($_POST['Usermodosit'])) {
			$_SESSION['uzenet']="";
			$_SESSION['editeduser']=$_POST['userID'][firstkey($_POST['Usermodosit'])];
			$_SESSION['vissza']="userlist.php";
			header('Location: useredit.php');
			exit;
		}
		if(isset($_POST['Useractivate'])) {
			$_SESSION['uzenet']="";
			//print_r($_POST['userID']);
			if(isset($_POST['kijelolt']))
			if(is_array($_POST['kijelolt'])) { 
				$j=0;
				foreach($_POST['kijelolt'] as $k=>$e) {
					//print_r("$k---$e");
					//print_r("X".$_POST['userID'][$k]."X");
					MyDatabase::getConnection()->multi_query("CALL useractivate('".$_POST['userID'][$k]."')");
					$j++;
				}
			}
		}
		
		if (checkuser("admin")==0){
			$_SESSION['uzenet']= "access denied";
		}
		
	?>
	
	<body>
		<table><tr HEIGHT="10"><td WIDTH="80%">Felhasználók listája</td><td WIDTH="20%"><?php include('kilepes.php');?></td></tr></table>
		
		<hr>
		
		<?php 
			printf($_SESSION['uzenet']);
		?>
		<hr>
		<form name='menu' method='post' action="userlist.php">
		<table>
		<tr>
		<td>
			<input type='submit'  class='button' name='Vissza' value='<< vissza' />
		</td>
		<td>
			<input type='submit'  class='button' name='Newuser' value='új felhasználó regisztrálása' />
		</td>
		<td>
		<input type='submit'  class='button' name='Useractivate' value='kijelöltek aktíválása' />
		</td>
		</tr>
		</table>
		
			<?php 
			
			if (checkuser("admin")==1){
				$query="CALL users1();";
				if (MyDatabase::getConnection()->multi_query($query)) {
						echo "<table id='one-column-emphasis'>";
						if ($result = MyDatabase::getConnection()->store_result()) {
							$j=0;
							while ($row = $result->fetch_row()) {
								echo "<tr>";
								echo "<td><input type=hidden name=userID[$j] value=$row[0]><input type=checkbox class=checkbox name=kijelolt[$j]></td><td>$row[0]</td>";
								for ($i=1;$i<5;$i++){
									echo "<td>".$row[$i]."</td>";
								}
								echo "<td><input type='submit'  class='tablazatbutton' name='Usermodosit[$j]' value='módosít' /></td>";
								$j++;
								echo "</tr>";
							}
							$result->free();
						}
						echo "</table>";
				}
				else{
					$_SESSION['uzenet']= MyDatabase::getConnection()->error;
					//printf(MyDatabase::getConnection()->error);
				}
			}


				
			?>
		</form>
	</body>
</html>

